<?php

namespace JLPay\Models\Openmerch\Register;

/**
 * 字段详情
 */
class FieldDetail
{
    protected ?string $fieldName = null;
    protected ?string $fieldValue = null;
    protected ?string $errorMsg = null;

    /**
     * 构造函数
     *
     * @param string|null $fieldName
     * @param string|null $fieldValue
     * @param string|null $errorMsg
     */
    public function __construct(?string $fieldName = null, ?string $fieldValue = null, ?string $errorMsg = null)
    {
        $this->fieldName = $fieldName;
        $this->fieldValue = $fieldValue;
        $this->errorMsg = $errorMsg;
    }

    /**
     * 设置字段名称
     *
     * @param string $fieldName
     * @return self
     */
    public function setFieldName(string $fieldName): self
    {
        $this->fieldName = $fieldName;
        return $this;
    }

    /**
     * 设置字段值
     *
     * @param string $fieldValue
     * @return self
     */
    public function setFieldValue(string $fieldValue): self
    {
        $this->fieldValue = $fieldValue;
        return $this;
    }

    /**
     * 设置错误信息
     *
     * @param string $errorMsg
     * @return self
     */
    public function setErrorMsg(string $errorMsg): self
    {
        $this->errorMsg = $errorMsg;
        return $this;
    }

    /**
     * 获取字段名称
     *
     * @return string|null
     */
    public function getFieldName(): ?string
    {
        return $this->fieldName;
    }

    /**
     * 获取字段值
     *
     * @return string|null
     */
    public function getFieldValue(): ?string
    {
        return $this->fieldValue;
    }

    /**
     * 获取错误信息
     *
     * @return string|null
     */
    public function getErrorMsg(): ?string
    {
        return $this->errorMsg;
    }

    /**
     * 转换为数组
     *
     * @return array
     */
    public function toArray(): array
    {
        return [
            'field_name' => $this->fieldName,
            'field_value' => $this->fieldValue,
            'error_msg' => $this->errorMsg
        ];
    }
} 